<template>
  <el-col class="app-v-center app-column" style="overflow-y: auto;">
    <el-row class="app-h-64px app-fill-width app-v-center" :gutter="10">
      <div class="px-2">
        <el-input v-model="name" placeholder="请输入用户名" />
      </div>
      <div class="pr-2">
        <el-input v-model="content" placeholder="请输入订单内容" />
      </div>
      <div class="pr-2">
        <el-button size="mini" type="info" @click="getOrderList">
          搜索
        </el-button>
      </div>
    </el-row>
    <el-table
      :data="orderList"
      class="app-flex-1"
      style="width: 100%;overflow-y: auto;"
    >
      <el-table-column
        prop="userId"
        align="center"
        label="用户Id"
        width="180"
      />
      <el-table-column
        prop="businessId"
        align="center"
        label="业务ID"
        width="180"
      />
      <el-table-column
        prop="businessType"
        align="center"
        label="业务类型"
        width="180"
      />
      <el-table-column
        prop="content"
        align="center"
        label="描述"
        width="180"
      />
      <el-table-column
        prop="balance"
        align="center"
        label="余额"
      >
        <template slot-scope="scope">
          <div>
            {{ scope.row.balance || 0 }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        align="center"
        label="时间"
      >
        <template slot-scope="scope">
          <div>
            {{ scope.row.createTime }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        width="200"
        label="操作"
      >
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)"
          >编辑</el-button> -->
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="mb-10 mt-5"
      background
      :current-page.sync="pageNo"
      :page-sizes="[10, 20, 50]"
      :page-size.sync="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="getOrderList"
      @current-change="getOrderList"
    />
  </el-col>
</template>

<script>
import { getOrderList,deleteOrder } from '@/api/user'
import { mapState } from 'vuex'
export default {
  data: () => ({
    rules: {
      name: [
        { required: true, message: '请输入员工姓名', trigger: 'blur' }
      ],
      mobile: [
        { required: true, message: '请输入员工电话', trigger: 'blur' }
      ],
      username: [
        { required: true, message: '请输入员工账号', trigger: 'blur' }
      ],
      roleId: [
        { required: true, message: '请选择员工角色', trigger: 'blur' }
      ]
    },
    isEdit: false,
    addUserDialog: false,
    orderList: [],
    pageNo: 1,
    pageSize: 10,
    total: 0,
    name: '',
    content: '',
    form: {
      name: '',
      mobile: '',
      username: '',
      password: '123456',
      roleId: null,
      roleName: '',
      userId: null
    }
  }),
  computed: {
    ...mapState('app',[
      'menuAndAuth'
    ])
  },
  mounted() {
    this.getOrderList()
  },
  methods: {
    toAddUser() {
      this.form = {
        name: '',
        mobile: '',
        username: '',
        password: '',
        roleId: null
      }
      this.isEdit = false
      this.addUserDialog = true
    },
    getOrderList() {
      const params = {
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        name: this.name,
        content: this.content
      }
      getOrderList(params).then(res => {
        if (res.code === 200) {
          this.orderList = res.data.dataList
          this.total = res.data.total
        }
      })
    },
    handleEdit(index,row) {
      this.isEdit = true
      this.form = row
      delete this.form.password
      this.addUserDialog = true
    },
    handleDelete(index,row) {
      this.$confirm(`确认删除业务${row.businessId}？`,'提示',{
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteOrder({ id: row.id }).then(res => {
          if (res.code === 200) {
            this.$message({ type: 'success',message: '已删除' })
            this.pageNo = 1
            this.getOrderList()
          }
        })
      }).catch(() => {
        this.$message('已取消')
      })
    }
  }
}
</script>
